Page({
  data: {
    isFinish: false,
  },
  onLoad({ id }) {
    this.getPassport(id)
  },
  async getPassport(id) {
    const { code, data } = await wx.http.get(`/visitor/${id}`)
    if (code !== 10000) return wx.utils.toast()
    // 请求成功
    this.setData({
      ...data,
    })
  },
  // 倒计时技术
  countDownFinish() {
    this.setData({
      isFinish: true,
    })
  },
  // 分享给朋友
  onShareAppMessage() {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index',
      imageUrl: 'https://enjoy-plus.oss-cn-beijing.aliyuncs.com/images/share_poster.png',
    }
  },
  // 保存图片到本地相册
  async saveImg() {
    // 将网路图片路径转换为小程序本地临时路径
    const res = await wx.getImageInfo({
      src: this.data.url,
    })
    // console.log(res.path);
    // res.path：小程序临时地址
    // 保存图片到相册
    wx.saveImageToPhotosAlbum({
      filePath: res.path,
    })
  },
})
